package com.itheima.IO流.写输出Output.异常finally都会执行;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class OutputDemo3 {
    public static void main(String[] args) {
        FileOutputStream fos=null;
        try{
            System.out.println(2/0);
            fos=new FileOutputStream("D:\\IdeaProjects\\JavaSE_Code\\day622_File&IO流\\a.txt");
            fos.write(97);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //finally语句里面的代码都会被执行
            if (fos!=null){
                try{
                    fos.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }
}
